package com.tetris.entities;

public class ShapeData {

    private int shapeSize;
    private int[][][] data;

    /**
     * 构造图形的数据
     * @param shapeSize 矩阵的大小（永远是正方形）
     * @param data 矩阵数组
     * @param rotationShapeCount 矩阵数组（包括其自身）变换的总数
     */
    public ShapeData(int shapeSize, int[][] data, int rotationShapeCount) {
        this.shapeSize = shapeSize;
        this.data = rotationMatrix(data, rotationShapeCount);
    }

    private int[][][] rotationMatrix(int[][] data, int rotationShapeCount){
        int[][][] res = new int[rotationShapeCount][][];
        res[0] = data;
        for (int i = 1; i < rotationShapeCount; i++) {
            res[i] = matrixTransformation(res[i-1]);
        }
        return res;
    }

    public static int[][] matrixTransformation(int[][] b) {
        int[][] temp = new int[b[0].length][b.length];
        for (int i = 0; i < b.length; i++) {
            for (int j = 0; j < b[i].length; j++) {
                temp[i][j]=b[b[i].length-j-1][i];
            }
        }
        return temp;
    }

    public int getShapeSize() {
        return this.shapeSize;
    }

    public int[][][] getData() {
        return this.data;
    }


    @Override
    public String toString() {
        return "{" +
            " shapeSize='" + getShapeSize() + "'" +
            ", data='" + getData() + "'" +
            "}";
    }

}